import Vue from 'vue'
import Vuex from 'vuex'
import { getMenus } from '@/api/user.js'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    isCollapse: false,
    menuTree: [],
  },
  getters: {
  },
  mutations: {
    changeCollapse(state) {
      state.isCollapse = !state.isCollapse
    },
    setMenuTree(state, menus) {
      state.menuTree = menus
    }
  },
  actions: {
    getMenuTree({ commit }) {
      return new Promise((resolve, reject) => {
        getMenus().then(res => {
          console.log('menusTree:', res);
          commit('setMenuTree', res.data)
          resolve()
        }).catch(err => {
          reject(err)
        })
      })
    }
  },
  modules: {
  }
})
